package com.kma.summer2012.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.kma.summer2012.client.Autorisation.CrumbsAuthorisationService;
import com.kma.summer2012.dao.CrumbsUserDAO;
import com.kma.summer2012.exceptions.CrumbsUniversalException;
import com.kma.summer2012.factory.DAOFactory;
import com.kma.summer2012.factory.SpringBeansFactory;
import com.kma.summer2012.model.CrumbsUser;
import com.kma.summer2012.server.proxy.Proxy;
import com.kma.summer2012.shared.model.UICrumbsUser;

import java.sql.SQLException;

/**
 * Created by IntelliJ IDEA.
 * User: Администратор
 * Date: 16.01.13
 * Time: 19:45
 * To change this template use File | Settings | File Templates.
 */
public class CrumbsAuthorisationServiceImpl extends RemoteServiceServlet implements CrumbsAuthorisationService {



    public UICrumbsUser getByLoginPassword(String login, String password)
    {
        DAOFactory factory = (DAOFactory) SpringBeansFactory.getInstance().getBeanByClass(DAOFactory.class);
        CrumbsUserDAO dao= (CrumbsUserDAO)factory.getCrumbsUserDAO();
        try {
            return Proxy.getInstance().createFromUser( dao.searchByLoginPassword(login, password));
        } catch (SQLException e) {
            throw new CrumbsUniversalException("Error in connection to database",e);  //To change body of catch statement use File | Settings | File Templates.
        }
    }


}
